<?php

namespace App\Http\Controllers\Api;

use Api\Controller\Allocation\AllocateDataController;
use App\Http\Controllers\Common\Internal;
use App\Models\Order;

use App\Models\Students\User;
use EasyWeChat\Factory;
use Illuminate\Http\Request;

class OrderController
{
    public function checkOrderStatus(Request $request)
    {
        $order_no = $request->input('order_no');
        $user = $request->user();
        $user_id = $user->id;
        $whereData = [
            'orderno' => $order_no,
            'user_id' => $user_id,
        ];
        $order =Order::where($whereData)->first();
        return response()->json([
            'code' => 200,
            'msg' => 'success',
            'data' => $order?$order->status:1
        ]);
    }



    //超时订单废弃
    public function orderAbandonment()
    {
        $time = date('Y-m-d H:i:s',time()-60*60*24);
        $order =Order::where('created_at','<',$time)->where('status',0)->get()->toArray();
        foreach ($order as $v){
            Order::where(['id'=>$v['id']])->update(['status'=>1]);
        }
    }


}
